package com.kitty.game.fight.task;

import com.kitty.game.fight.bean.Fight;
import com.kitty.game.fight.bean.FightObject;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.fight.message.ReqFightDoAction;
import com.kitty.game.fight.service.FightExecutorService;

public class AutoChuShouTask implements FightingTask {

    private ReqFightDoAction fightDoAction;
    private Fight fight;

    public AutoChuShouTask(ReqFightDoAction ReqFightDoAction, Fight fight) {
        this.fightDoAction = ReqFightDoAction;
        this.fight = fight;
    }

    @Override
    public void run() {
        SpringUtils.getBean(FightExecutorService.class).addFightTask(fight, () -> {
            FightObject fightObject = fight.queryFightObject(fightDoAction.getAttackerId());
            if (fightObject != null) {
                SpringUtils.getFightService().doAction(fightDoAction);
                if (fightObject.isPet()) {
                    fight.removePetTask(fightDoAction.getAttackerId());
                } else if (fightObject.isPlayer()) {
                    fight.removeHostTask(fightDoAction.getAttackerId());
                }
            }
        });
    }

}
